//homeVuex.js
import {GlobalDefinitions} from "../../GlobalDefinitions";
import {autoRefreshTokenFetch} from "../../utils/autoRefreshTokenFetch";

const state={   //要设置的全局访问的state对象
    showFooter: true,
    taskByUnit:{}
    //要设置的初始属性值
};
const getters = {   //实时监听state值的变化(最新状态)
    isShow(state) {  //承载变化的showFooter的值
        return state.showFooter
    },
    getTaskByUnit(){  //承载变化的changebleNum的值
        return state.taskByUnit
    }
};

const mutations = {
    show(state) {   //自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
        state.showFooter = true;
    },
    hide(state) {  //同上
        state.showFooter = false;
    },
    getTaskByUnit(state,data){ //同上，这里面的参数除了state之外还传了需要增加的值sum
        state.taskByUnit=data;
    }
};
const actions = {
    hideFooter(context) {  //自定义触发mutations里函数的方法，context与store 实例具有相同方法和属性
        context.commit('hide');
    },
    showFooter(context) {  //同上注释
        context.commit('show');
    },
    getTaskByUnit(context,num){   //同上注释，num为要变化的形参
        console.log("getTaskByUnit:basePath   ",(window as GlobalDefinitions).basePath );
        const request = {
            method: 'GET',
            credentials: 'include',
            headers: {
                'Authorization': (window as GlobalDefinitions).authorization,
                'Accept': 'application/json, text/plain, */*',
                'Content-Type': 'application/json',
                'Cache-Control': ' no-cache'
            },
            url: (window as GlobalDefinitions).basePath+"/api/preparation/v1/sec/getTaskByUnitId?unitId=794",
        };
        autoRefreshTokenFetch(request).then((response:any)=>{
            console.log("autoRefreshTokenFetch: response: ",response.data);
            context.commit('getTaskByUnit',response.data)
        }).catch((error:any)=>{
            console.log("autoRefreshTokenFetch: error: ",error)
        });
    }
};
export default {
    namespaced: true, //用于在全局引用此文里的方法时标识这一个的文件名
    state,
    getters,
    mutations,
    actions
}